package com.power.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.power.manager.CustomerManager;
import com.power.mapper.TCustomerMapper;
import com.power.model.TCustomer;
import com.power.query.CustomerQuery;
import com.power.result.CustomerExcelData;
import com.power.service.CustomerService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerManager customerManager;

    @Resource
    private TCustomerMapper tCustomerMapper;

    @Override
    public Boolean addCustomer(CustomerQuery customerQuery) {
        return customerManager.addCustomer(customerQuery);
    }

    @Override
    public PageInfo<TCustomer> selectCustomerListByPage(Integer currentPage, Integer pageSize, CustomerQuery customerQuery) {
        PageHelper.startPage(currentPage, pageSize);
        List<TCustomer> customerList = tCustomerMapper.selectAllByPage();
        PageInfo<TCustomer> pageInfo = new PageInfo<>(customerList);
        return pageInfo;
    }

    @Override
    public List<CustomerExcelData> getCustomerByExcel(List<String> idsList) {
        List<CustomerExcelData> customerExcelDataList = new ArrayList();
        List<TCustomer> tCustomerList = tCustomerMapper.selectCustomerExcel(idsList);
        for (TCustomer tCustomer : tCustomerList) {
            CustomerExcelData customerExcelData = new CustomerExcelData();
            //这里需要把TCustomer里面的数据赋值给customerExcelData
            customerExcelDataList.add(customerExcelData);
        }
        return customerExcelDataList;
    }
}
